package edu.buaa.act.travel.m.page;

import edu.buaa.act.travel.m.Constants;
import edu.buaa.act.travel.m.R;
import edu.buaa.act.travel.m.adapter.SurroundsAdapter;
import edu.buaa.act.travel.m.model.SurroundsModel;
import edu.buaa.act.travel.m.service.DataService;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ListView;

public class SurroundHotelActivity extends Activity{
	
	protected static final int DIALOG_WAIT = 900;
	protected static final int DIALOG_GET_DATA_FAIL = 901;
	
	private ListView mListSurrounds;
	private SurroundsAdapter mSurroundsAdapter;
	
	private Handler mHandler = new Handler() {
		
		@Override
		public void handleMessage(final Message msg) {
			try {
				dismissDialog(DIALOG_WAIT);
			} catch(Exception e) {
				// no dialog shown
			}
			switch(msg.what) {
			case Constants.MESSAGE_GET_DATA_SUCCESS:
				setup((String) msg.obj);
				break;
			case Constants.MESSAGE_GET_DATA_FAIL:
				break;
			}
		}
	};
	
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.surround_list_activity);

        mListSurrounds = (ListView) findViewById(R.id.list_surround);
        getSurrounds();
    }
	
	
	private void setup(final String result) {
		mSurroundsAdapter = new SurroundsAdapter(this, new SurroundsModel(result).getSurroundsList());
		mListSurrounds.setAdapter(mSurroundsAdapter);
	}
	
	private void getSurrounds() {
		showDialog(DIALOG_WAIT);
		DataService.get(Constants.URL_GET_SURROUNDS_HOTEL, 
				mHandler, 
				Constants.MESSAGE_GET_DATA_SUCCESS, 
				Constants.MESSAGE_GET_DATA_FAIL);
	}
	
}
